﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Schism
{
    public static class SpriteSheetHelper
    {
        public static Texture2D Retreive(Texture2D spriteSheet, Rectangle source)
        {
            RenderTarget2D target = new RenderTarget2D(ObjectHolder.GameObject.GraphicsDevice, source.Width, source.Height, false, SurfaceFormat.Color, DepthFormat.None);

            ObjectHolder.GameObject.GraphicsDevice.SetRenderTarget(target);
            ObjectHolder.GameObject.GraphicsDevice.Clear(new Color(0xff, 0xff,0xff, 0x40));
            using (SpriteBatch b = new SpriteBatch(target.GraphicsDevice))
            {
                b.Begin();
                b.Draw(spriteSheet, new Rectangle(0, 0, source.Width, source.Height), source, Color.White);
                b.End();
            };

            ObjectHolder.GameObject.GraphicsDevice.SetRenderTarget(null);
            return target;
        }

    }
}
